home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
asmutil
/
chasm4.zip
/
PRIMER.DOC
< prev
next >
Wrap
Text File
|
1984-09-13
|
49KB
|
1,783 lines
An Assembly Language Primer
(C) 1983 by David Whitman
TABLE OF CONTENTS
Introduction.......................................2
The Computer As A Bit Pattern Manipulator..........3
Digression: A Notation System for Bit Patterns.....5
Addressing Memory..................................7
The Contents of Memory: Data and Programs..........8
The Dawn of Assembly Language......................9
The 8088..........................................11
Assembly Language Syntax..........................14
The Stack.........................................17
Software Interrupts...............................19
Pseudo-Operations.................................21
Tutorial..........................................23
2
>>INTRODUCTION<<
Many people requesting CHASM have indicated that they are
interested in *learning* assembly language. They are beginners,
and have little idea just where to start. This primer is
directed to those users. Experienced users will probably find
little here that they do not already know.
Being a primer, this text will not teach you everything there is
to know about assembly language programming. It's purpose is to
give you some of the vocabulary and general ideas which will help
you on your way.
I must make a small caveat: I consider myself a relative beginner
in assembly language programming. A big part of the reason for
writing CHASM was to try and learn this branch of programming
from the inside out. I think I've learned quite a bit, but it's
quite possible that some of the ideas I relate here may have some
small, or even large, flaws in them. Nonetheless, I have
produced a number of working assembly language programs by
following the ideas presented here.
3
>>THE COMPUTER AS A BIT PATTERN MANIPULATOR.<<
We all have some conception about what a computer does. On one
level, it may be thought of as a machine which can execute BASIC
programs. Another idea is that the computer is a number
crunching device. As I write this primer, I'm using my computer
as a word processor.
I'd like to introduce a more general concept of just what sort of
machine a computer is: a bit pattern manipulator.
I'm certain that everyone has been introduced to the idea of a
*bit*. (Note: Throughout this primer, a word enclosed in
*asterisks* is to be read as if it were in italics.) A bit has
two states: on and off, typically represented with the symbols
"1" and "0". In this context, DON'T think of 1 and 0 as
numbers. They are merely convenient shorthand labels for the
state of a bit.
The memory of your computer consists of a huge collection of
bits, each of which could be in either the 1 or 0 (on or off)
state.
At the heart of your computer is an 8088 microprocessor chip,
made by Intel. What this chip can do is manipulate the bits
which make up the memory of the computer.
The 8088 likes to handle bits in chunks, and so we'll introduce
special names for the two sizes of bit chunks the 8088 is most
happy with. A *byte* will refer to a collection of eight bits.
A *word* consists of two bytes, or equivalently, sixteen bits.
A collection of bits holds a pattern, determined by the state of
its individual bits. Here are some typical byte long patterns:
10101010 11111111 00001111
If you've had a course in probability, it's quite easy to work
out that there are 256 possible patterns that a byte could hold.
similarly, a word can hold 65,536 different patterns.
4
All right, now for the single most important idea in assembly
language programming. Are you sitting down? These bit patterns
can be used to represent other sets of things, by mapping each
pattern onto a member of the other set. Doesn't sound like much,
but IBM has made *BILLIONS* off this idea.
For example, by mapping the patterns a word can hold onto the set
of integers, you can represent either the numbers from 0 to 65535
or -32768 to 32767, depending on the exact mapping you use. You
might recognize these number ranges as the range of possible line
numbers, and the possible values of an integer variable, in BASIC
programs. This explains these somewhat arbitrary seeming limits:
BASIC uses words of memory to hold line numbers and integer
variables.
As another example, you could map the patterns a byte can hold
onto a series of arbitrarily chosen little pictures which might
be displayed on a video screen. If you look in appendix G of
your BASIC manual, you'll notice that there are *exactly* 256
different characters that can be displayed on your screen. Your
computer uses a byte of memory to tell it what character to
display at each location of the video screen.
Without getting too far ahead of myself, I'll just casually
mention that there are about 256 fundamental ways the 8088 can
manipulate the bit patterns stored in memory. This suggests
another mapping which we'll discuss in more detail later.
The point of this discussion is that we can use bit patterns to
represent anything we want, and by manipulating the patterns in
different ways, we can produce results which have significance in
terms of what we're choosing to represent.
5
>>DIGRESSION: A NOTATION SYSTEM FOR BIT PATTERNS<<
Because of their importance, it would be nice to have a
convenient way to represent the various bit patterns we'll be
talking about. We already have one way, by listing the states of
the individual bits as a series of 1's and 0's. This system is
somewhat clumsy, and error prone. Are the following word
patterns identical or different?
1111111011111111 1111111101111111
You probably had trouble telling them apart. It's easier to tell
that they're different by breaking them down into more manageable
pieces, and comparing the pieces. Here are the same two patterns
broken down into four bit chunks:
1111 1110 1111 1111 1111 1111 0111 1111
Some clown has given the name *nybble* to a chunk of 4 bits,
presumably because 4 bits are half a byte. A nybble is fairly
easy to handle. There are only 16 possible nybble long patterns,
and most people can distinguish between the patterns quite
easily.
Each nybble pattern has been given a unique symbol agreed upon by
computer scientists. The first 10 patterns were given symbols
"0" through "9", and when they ran out of digit style symbols,
they used the letters "A" through "F" for the last six patterns.
Below is the "nybble pattern code":
0000 = 0 0001 = 1 0010 = 2 0011 = 3
0100 = 4 0101 = 5 0110 = 6 0111 = 7
1000 = 8 1001 = 9 1010 = A 1011 = B
1100 = C 1101 = D 1110 = E 1111 = F
Using the nybble code, we can represent the two similar word
patterns given above, with the following more manageable
shorthand versions:
FEFF FF7F